package com.leung.grpcService;


import com.leung.protoService.HelloGrpc;
import com.leung.protoService.HelloOuterClass;
import io.grpc.Channel;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

/**
 * @author 丨一
 * @version 1.0
 * @title HelloClientService
 * @description:
 * @date 2025/3/15 下午12:00
 */

@Service
public class HelloClientService {

    @GrpcClient("grpc-server")
    private Channel serverChannel;

    public String sendMessage(String name) {
        //1. 获取存根
        HelloGrpc.HelloBlockingStub stub = HelloGrpc.newBlockingStub(serverChannel);
        
        //2. 构建请求体
        HelloOuterClass.HelloRequest request = HelloOuterClass.HelloRequest.newBuilder().setName(name).build();
        HelloOuterClass.HelloReply helloReply = stub.sayHello(request);
        return helloReply.getMessage();
    }
    
    
    
}
